﻿public static class PathUtil
{
    private static int dirNameIndex;

    /// <summary>
    /// 获取路径文件夹名字 
    /// 如: DirName("/aa/bb/cc/dd") => "dd"
    /// </summary>
    /// <param name="path">路径</param>
    /// <returns></returns>
    public static string DirName(string path) 
    {
        path = ToSame(path);
        dirNameIndex = path.LastIndexOf("/");
        if (dirNameIndex < 0) return "";
        return path.Substring(0, dirNameIndex);
    }

    /// <summary>
    /// 转换为通用路径 
    /// 如 "aa\\bb/cc\\dd" => "aa/bb/cc/cc"
    /// </summary>
    /// <param name="fullName"></param>
    /// <returns></returns>
    public static string ToSame(string fullName)
    {
        return fullName.Replace("\\", "/");
    }
}
